import {
  ViewController,
  ITreeExpViewEvent,
  ITreeExpViewState,
  ViewEngineBase,
  ITreeExpBarController,
} from '@ibiz-template/runtime';
import { IAppDETreeExplorerView } from '@ibiz/model-core';

export class TreeExpViewEngine extends ViewEngineBase {
  /**
   * 树导航视图控制器
   *
   * @protected
   * @type {ViewController<
   *     IAppDETreeExplorerView,
   *     ITreeExpViewState,
   *     ITreeExpViewEvent
   *   >}
   * @memberof TreeExpViewEngine
   */
  protected declare view: ViewController<
    IAppDETreeExplorerView,
    ITreeExpViewState,
    ITreeExpViewEvent
  >;

  /**
   * 树导航栏
   *
   * @readonly
   * @memberof TreeExpViewEngine
   */
  get treeExpBar(): ITreeExpBarController {
    return this.view.getController('treeexpbar') as ITreeExpBarController;
  }

  async onCreated(): Promise<void> {
    await super.onCreated();
    const { childNames } = this.view;
    childNames.push('treeexpbar');
    if (!this.view.slotProps.treeexpbar) {
      this.view.slotProps.treeexpbar = {};
    }
    this.view.slotProps.treeexpbar.srfnav = this.view.state.srfnav;
  }

  async onMounted(): Promise<void> {
    await super.onMounted();
    const { model } = this.view;
    // 默认加载
    if (!this.view.state.noLoadDefault && model.loadDefault) {
      this.treeExpBar.load();
    }
  }
}
